// 订单相关类型定义（收货开票）

export interface Order {
  id: number;
  tenantId: number;
  siteId?: number;
  orderNo: string;
  goodsCode?: string;

  // 站点信息
  departureSiteId?: number;
  departureSiteName?: string;
  arrivalSiteId?: number;
  arrivalSiteName?: string;

  // 发货信息
  senderName: string;
  senderPhone: string;

  // 收货信息
  receiverName: string;
  receiverPhone: string;
  deliveryType: string; // 配送方式：DELIVERY-送货上门, PICKUP-到站自提
  deliveryOptions?: string; // 配送附加选项（逗号分隔）：SIGN_RECEIPT-签回单, PRINT_RECEIPT-打收条
  receiverAddress?: string; // 收货地址（送货方式时填写）

  // 货物信息
  goodsName: string;
  goodsPackage?: string;
  goodsPieces: number;

  // 运费信息
  freightAmount: number; // 实收运费（发货站点收取）
  settlementAmount: number; // 结算运费（给到货站点）
  collectionAmount?: number;
  paymentMethod: string;

  // 订单状态
  orderStatus: OrderStatus;

  // 车辆和司机
  driverId?: number;
  driverName?: string;
  driverPhone?: string;
  deliveryDriverId?: number; // 送货司机ID
  deliveryDriverName?: string; // 送货司机姓名
  deliveryDriverPhone?: string; // 送货司机电话
  vehicleId?: number;
  vehiclePlate?: string;
  loadedAt?: string;
  dispatchTime?: string; // 发货时间
  arrivalTime?: string; // 到货时间
  assignTime?: string;
  deliveryAssignTime?: string; // 送货司机分配时间

  // 完成信息
  deliveryTime?: string;

  // 取消信息
  cancelReason?: string;
  cancelTime?: string;

  // 开票员
  issuerId?: number;
  issuerName?: string;

  remark?: string;
  createBy: number;
  createTime: string;
  updateBy?: number;
  updateTime: string;
}

export type OrderStatus =
  | "RECEIVED" // 已收货（待装车）
  | "LOADED" // 已装车
  | "IN_TRANSIT" // 运输中
  | "ARRIVED" // 到货
  | "DELIVERING" // 派送中/待取货
  | "COMPLETED" // 已完成
  | "CANCELLED"; // 已取消

export interface OrderCreateParams {
  siteId?: number;
  goodsCode?: string;
  departureSiteId?: number;
  departureSiteName?: string;
  arrivalSiteId?: number;
  arrivalSiteName?: string;
  senderName: string;
  senderPhone: string;
  receiverName: string;
  receiverPhone: string;
  deliveryType: string;
  deliveryOptions?: string;
  receiverAddress?: string;
  goodsName: string;
  goodsPackage?: string;
  goodsPieces: number;
  freightAmount: number; // 实收运费
  settlementAmount: number; // 结算运费
  collectionAmount?: number;
  paymentMethod: string;
  driverId?: number;
  remark?: string;
}

export interface OrderUpdateParams {
  goodsCode?: string;
  departureSiteId?: number;
  departureSiteName?: string;
  arrivalSiteId?: number;
  arrivalSiteName?: string;
  senderName?: string;
  senderPhone?: string;
  receiverName?: string;
  receiverPhone?: string;
  deliveryType?: string;
  deliveryOptions?: string;
  receiverAddress?: string;
  goodsName?: string;
  goodsPackage?: string;
  goodsPieces?: number;
  freightAmount?: number; // 实收运费
  settlementAmount?: number; // 结算运费
  collectionAmount?: number;
  paymentMethod?: string;
  driverId?: number;
  remark?: string;
}

export interface OrderQueryParams {
  current?: number;
  size?: number;
  orderStatus?: OrderStatus;
  orderNo?: string;
  goodsCode?: string;
  departureSiteId?: number;
  arrivalSiteId?: number;
  driverId?: number;
  vehicleId?: number;
  vehiclePlate?: string;
  paymentMethod?: string;
  startTime?: string;
  endTime?: string;
  keyword?: string;
  senderName?: string;
  receiverName?: string;
  senderPhone?: string;
  receiverPhone?: string;
  driverName?: string;
  driverPhone?: string;
  goodsName?: string;
  issuerName?: string;
}

export interface OrderAssignRequest {
  driverId: number;
  // 注意：车辆分配留到后续运单装车功能
}

// 订单状态配置
export const ORDER_STATUS_CONFIG = {
  RECEIVED: {
    label: "已收货",
    color: "gold",
  },
  LOADED: {
    label: "已装车",
    color: "cyan",
  },
  IN_TRANSIT: {
    label: "运输中",
    color: "blue",
  },
  ARRIVED: {
    label: "到货",
    color: "purple",
  },
  DELIVERING: {
    label: "派送中",
    color: "geekblue",
  },
  COMPLETED: {
    label: "已完成",
    color: "green",
  },
  CANCELLED: {
    label: "已取消",
    color: "red",
  },
};

// 配送方式配置
export const DELIVERY_TYPE_CONFIG = {
  DELIVERY: {
    label: "送货上门",
    value: "DELIVERY",
  },
  PICKUP: {
    label: "到站自提",
    value: "PICKUP",
  },
};
